"""
@name : 3.线程锁
@author : wenyao
@projectname: sanchuanglianxi
"""
#锁机制
#解决多线程之间数据完整性和状态同步的简单方案

#不一致读取数据
from threading import Thread
import time
num = 0

def sum_num(i):
   global num
   time.sleep(1)
   num += i
   print(num)

list = []
for i in range(6):
    t = Thread(target = sum_num, args=(i,))
    list.append(t)
    t.start()

# [root@localhost process-thread]# python3 thread1.py
# 2
# 5
# 10
# 10
# 11
# 15

#以上代码出现了脏数据
#为了避免数据不一致的情况，引入了锁的概念

